package com.aipp.mall.h5.controller;

import com.aipp.mall.h5.domain.entity.MemberCart;
import com.aipp.mall.h5.domain.vo.MemberCartVO;
import com.aipp.mall.h5.service.H5MemberCartService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/h5/cart")
public class H5MemberCartController {

    @Resource
    private H5MemberCartService h5MemberCartService;


    /**
     * 添加购物车
     *
     * @return 购物车商品
     */
    @PostMapping("add")
    public ResponseEntity<Integer> add(@RequestBody MemberCart memberCart) {
        return ResponseEntity.ok(h5MemberCartService.insert(memberCart));
    }

    /**
     * 修改购物车
     *
     * @return 是否修改
     */
    @PostMapping("modify")
    public ResponseEntity<Integer> modify(@Valid @RequestBody MemberCart memberCart) {
        return ResponseEntity.ok(h5MemberCartService.update(memberCart));
    }

    /**
     * 修改购物车
     *
     * @return 是否修改
     */
    @DeleteMapping("remove")
    public ResponseEntity<Integer> remove(@RequestBody String ids) {
        return ResponseEntity.ok(h5MemberCartService.deleteByIds(ids));
    }

    /**
     * 购物车列表
     *
     * @return 购物车列表
     */
    @GetMapping("list")
    public ResponseEntity<List<MemberCartVO>> cartList() {
        return ResponseEntity.ok(h5MemberCartService.cartList());
    }


}
